<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<?php

	include("class/conmssql.php");
	include("class/function.php");
	

	
////////////////////insert User ///////////////////////////////////	
if($_REQUEST['adduser'] != '')
{

$id = '';
$dateadd = date("Y-m-d H:i:s"); 
	$data ="
			fkRole
           ,fkProject
           ,sUserName
		   ,sLoweredUserName
		   ,sCreatedBy
           ,dtCreate
           ,bActive
	";
	$dataprocess = "'{$_REQUEST['projectlocaltion']}','{$_REQUEST['typeRole']}','{$_REQUEST['useradd']}','{$_REQUEST['useradd']}','system','$dateadd','1'";
	
	$sql = MssqlInsert("[dbo].[Usernames]",$data,$dataprocess);	
	
	$res = mssql_query('SELECT @@identity AS id');
	
	

		if ($row = mssql_fetch_row($res)) 
		{
			$id = trim($row[0]);
			
		}
		//echo $id;	
	if($id != '')
	{
	///[dbo].[UserDetail] 
	$data1 = "
		    [pkUser]
		   ,[sPassword]
           ,[sFirstname]
           ,[sLastname]
           ,[sAddress]
           ,[sMobileNumber]
           ,[sEmail]
           ,[sLoweredEmail]
           ,[sPasswordQuestion]
           ,[sPasswordAnswer]
           ,[bIsApproved]
           ,[sCreatedBy]
           ,[dtCreate]
           ,[sComment],bIsLockedOut,iAttemptToLogin
	";

	$dataprocess1 = "'$id','{$_REQUEST['password']}',
							 '{$_REQUEST['FristName']}',
							 '{$_REQUEST['LastName']}',
							 '{$_REQUEST['Address']}',
							 '{$_REQUEST['Mobile']}',
							 '{$_REQUEST['mail']}',
							  '{$_REQUEST['mail']}',
							 '{$_REQUEST['PasswordQuestion']}',
							 '{$_REQUEST['PasswordAnswer']}',
							 '1','system','$dateadd',
							 '{$_REQUEST['Comment']}','0','0'
							";
		$sql = MssqlInsert("[dbo].[UserDetail]",$data1,$dataprocess1);

		
	}					
							
}






/////////////////////////Update User////////////////////////////////////////////
if($_REQUEST['updatedata'] != '')
{			
$dateuap = date("Y-m-d H:i:s"); 
	$data =
			"sUserName   =	'{$_REQUEST['useradd']}',
			 fkRole		=	 '{$_REQUEST['typeRole']}',
			 fkProject	=	 '{$_REQUEST['projectlocaltion']}',
			 dtLastUpDate = '$dateuap'
		";
	UpDateMssql("[dbo].[Usernames]",$data,"pkUser = '{$_REQUEST['iduserdata']}'");						 
							 
	$date1 ="
			sPassword   =	 '{$_REQUEST['password']}',
			sFirstname	=	 '{$_REQUEST['FristName']}',
			sLastname	=	 '{$_REQUEST['LastName']}',
			sPasswordQuestion =	'{$_REQUEST['PasswordQuestion']}',
			sPasswordAnswer	  =	 '{$_REQUEST['PasswordAnswer']}',
			sAddress	=	 '{$_REQUEST['address']}',
			sEmail		=	 '{$_REQUEST['mail']}',
			sMobileNumber	=	 '{$_REQUEST['Mobile']}',			
			sComment		=	'{$_REQUEST['comment']}',
			dtLastUpDate   = '$dateuap'
	";
	
	UpDateMssql("[dbo].[UserDetail]",$date1,"pkUser = '{$_REQUEST['iduserdata']}'");		
	
}
	

////////////////////insert Project ///////////////////////////////////

if($_REQUEST['addproject'] != '')
{
$pic = '';
	if(move_uploaded_file($_FILES["filUpload"]["tmp_name"],"Pic/newdam".$_FILES["filUpload"]["name"]))
	{
		$pic  = "Pic/newdam".$_FILES["filUpload"]["name"];
	}

$dateadd = date("Y-m-d H:i:s"); 




	$data = "[sProjectName]
           ,[sAddress]
           ,[sTelePhone]
           ,[sMobilePhone]
           ,[sEmail]
           ,[sCreatedBy]
           ,[dtCreate]
           ,[sImageURL]
           ,[iPZCount]
           ,[iIncCount]
           ,[iSetCount]
           ,[bActive]
           ,[detailProject]
           ,[lat]
           ,[lot]";
	$dataprocess1 = "
	'{$_REQUEST['projectname']}',
	'{$_REQUEST['localtionname']}',
	'{$_REQUEST['phone']}',
	'{$_REQUEST['mobile']}',
	'{$_REQUEST['mail']}',
	'$_SESSION[user]',
	'$dateadd',
	'$pic',
	'{$_REQUEST['numberPiezometer']}',
	'{$_REQUEST['numberInclinometer']}',
	'{$_REQUEST['numberSettlement']}',
	'{$_REQUEST['detailProject']}',
	'1',
	'{$_REQUEST['lat']}',
	'{$_REQUEST['lot']}'
	
	";

	$sql = MssqlInsert("[dbo].[Project]",$data,$dataprocess1);
}
	
	
	
	
	
	
	
	
?>

<?php

if($_REQUEST['page'] != "")
  {
 ?>   
 <script type="text/javascript">
      $(function(){
       // window.location = "admin.php?page=<?=$page?>&&act=<?=$act?>";
        });
      </script>
    
 <?php  
}

?>